package cst.a703xmq.zyfypt_703xmq.Activity;

import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentPagerAdapter;
import android.support.v4.view.ViewPager;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.ImageButton;
import android.widget.LinearLayout;
import android.widget.Toast;

import java.util.ArrayList;
import java.util.List;
import cst.a703xmq.zyfypt_703xmq.Fragment.FocusListFragment;

import cst.a703xmq.zyfypt_703xmq.R;

public class FocusActivity extends AppCompatActivity {
    private LinearLayout  layout1;
    private ImageButton ib1;
    private ViewPager vp;
    private List<Fragment> listfragment;
    private FragmentPagerAdapter fpadapter;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_focus);

        init();
        initEvents();
        initFragment();
    }

    private void initFragment() {
        listfragment=new ArrayList<Fragment>();
        listfragment.add(new FocusListFragment());

        fpadapter=new FragmentPagerAdapter(getSupportFragmentManager()) {
            @Override
            public Fragment getItem(int position) {
                return listfragment.get(position);
            }

            @Override
            public int getCount() {
                return listfragment.size();
            }
        };
        vp.setAdapter(fpadapter);
        vp.addOnPageChangeListener(new ViewPager.OnPageChangeListener() {
            @Override
            public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {

            }

            @Override
            public void onPageSelected(int position) {
                System.out.println("----"+String.valueOf(position));
                vp.setCurrentItem(position);
            }

            @Override
            public void onPageScrollStateChanged(int state) {

            }
        });

    }

    View.OnClickListener  onClickListener =new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            switch (view.getId())
            {
                case R.id.layout1:
                    Toast.makeText(FocusActivity.this, "我的关注", Toast.LENGTH_SHORT).show();
                    break;
            }
        }
    };
    private void initEvents() {
        layout1.setOnClickListener(onClickListener);
    }

    private void init() {
        layout1=(LinearLayout)findViewById(R.id.layout1);

        ib1=(ImageButton)findViewById(R.id.imageButton1);

        vp=(ViewPager)findViewById(R.id.focus_viewPager);
    }
}